	package gui.engraving;


import java.awt.Toolkit;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;

import clients.RPCClient;

import java.awt.SystemColor;
import java.awt.Color;

/**
 * @author Idan
 * Engrave station Frame
 */
public class EngravingFrame extends JFrame
{

	 public static RPCClient engravingClient = null;
	    private EngravingPanel engravingPanel;
	    

	    public EngravingFrame()
	    {
	    	getContentPane().setBackground(new Color(173, 216, 230));
	    	setIconImage(Toolkit.getDefaultToolkit().getImage(EngravingFrame.class.getResource("/graphics/Spearhead.png")));
	    	setTitle("ח.נ.י.ת");
	        initComponents();
	        this.setExtendedState(javax.swing.JFrame.MAXIMIZED_BOTH);
	    }


	    @SuppressWarnings("unchecked")
	 
	    private void initComponents()
	    {

	        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

	        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
	        getContentPane().setLayout(layout);
	        layout.setHorizontalGroup(
	            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
	            .addGap(0, 559, Short.MAX_VALUE)
	        );
	        layout.setVerticalGroup(
	            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
	            .addGap(0, 481, Short.MAX_VALUE)
	        );

	        pack();
	    }

	    public static void main(String args[])
	    {

	        try {
	            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
	                if ("Nimbus".equals(info.getName())) {
	                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
	                    break;
	                }
	            }
	        } catch (ClassNotFoundException ex) {
	            java.util.logging.Logger.getLogger(EngravingFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
	        } catch (InstantiationException ex) {
	            java.util.logging.Logger.getLogger(EngravingFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
	        } catch (IllegalAccessException ex) {
	            java.util.logging.Logger.getLogger(EngravingFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
	        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
	            java.util.logging.Logger.getLogger(EngravingFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
	        }
	      
	        
	        /** Create client and connect to the Server*/

	        
	            try
	            {
	               engravingClient = new RPCClient();
	               if  (engravingClient== null)
	            	   System.exit(0);
	      

	               // get list of orders
	           }
	           catch  (Exception e) 
	           {
	             //e.printStackTrace();
	           }
	            
	        
	        /* Create and display the form */
	            SwingUtilities.invokeLater(new Runnable()
	        {
	            public void run() 
	            {
	                EngravingFrame engravingFrame = new EngravingFrame();
	                engravingFrame.engravingPanel = new EngravingPanel(engravingFrame,engravingClient); 
	                engravingFrame.setContentPane(engravingFrame.engravingPanel);
	                
	                // call functions
	                ArrayList<Object> response = initializeAllFields();
	  
	   

	            
	            if (response.get(0).toString().equalsIgnoreCase("initializeAllFieldsEngraving"))
	            {		
	                    engravingFrame.engravingPanel.setVariables(response); 
	                    engravingFrame.setVisible(true);  
	            }
	            else
	            	JOptionPane.showMessageDialog(engravingFrame.engravingPanel,
						    "שגיאה בחיבור לשרת.","שגיאה",JOptionPane.ERROR_MESSAGE);
	     
	           
	                //set visible
	            }
	        });
	    }

	   
	    /**
	     * Gets the initialization data for all GUI Panels
	     */
	    private static ArrayList<Object> initializeAllFields()
	    {
	         ArrayList<Object> message = new ArrayList<Object>();
	        message.add("initializeAllFieldsEngraving");
	         
	        try 
	        {
	    
	        	ArrayList<Object> response = engravingClient.call(message);
	     
	     
	            return  response; 
	        } catch (Exception ex) {
	            Logger.getLogger(EngravingFrame.class.getName()).log(Level.SEVERE, null, ex);
	        }
	        
	       ArrayList<Object> failed = new ArrayList<Object>();
	       failed.add("initializeAllFieldsEngraving");
	       failed.add("Failed in initializeAllFieldsEngraving");
	        
	          return failed;
	    }


}
